<?php

/**
 * Image management Component 
 * @author LeDat <qtdat2.9@gmail.com>
 */

class ComImgManController extends AController {

    public function actionIndex() {
        $this->layout ='admin_none';
        $this->render('index');
    }

    public function actionUpload() {
        $objComImgMan = new DComImgMan();
        $objComImgMan->setAttributes(array(
            'fileName' => 'file_upload'
        ));

        if ($objComImgMan->validate()) {
            echo 'success';
        } else {
            echo $objComImgMan->getError('fileName');
        }
        
        Yii::app()->end();
    }
    
    public function actionShowFiles() {
        $dir = Yii::app()->params['newsletter_dir'];
        $model = new DComImgMan();
        
        $this->renderPartial('_view_thumb', array(
            'images' => $model->getFiles($dir),
        ));
    }
    
    public function actionDeleteFile() {
        if (isset($_POST['name'])) {
            $model = new DComImgMan();
            
            if ($model->deleteFile($_POST['name'])) {
                echo 'success';
            } else {
                echo $model->errorMsg;
            }
        }
    }

}